// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class GameLoad extends cc.Component {

    @property(cc.Node)
    barNode: cc.Node = null;
    @property(cc.Node)
    bar: cc.Node = null;
    @property(cc.Node)
    startBtn: cc.Node = null;
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.loadRes();
    }

    loadRes(){
        let tempCompLete = 0;
        let tempTotal = 0;
        cc.director.preloadScene("Game", (complete, total)=>{
            cc.log(complete, total)
            this.setBarProg(Number((complete / (total)).toFixed(2)));
            if (complete == total) {
                tempCompLete = total;
                tempTotal = total;
            }
        },(error)=>{
            //cc.log(error)
            this.startBtn.active = true;
        })
    }
    setBarProg(prog: number) {
        let px = prog * 608;
        if (px < this.bar.x) return;
        this.bar.x = px;
    }

    enterGame() {
        cc.director.loadScene("Game");
    }

    // update (dt) {}
}
